/**
 * PHOSIDE: PHosphorylation Site IDentification Engine.
 * Copyright 2009 Digital Biology Lab, University of Missouri.
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 3 of the License, or (at your option) any later
 * version. <p/> This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License for more
 * details.
 */


package phoside.ui;

import phoside.classify.result.ResultInterpreter;

/**
 *
 * @author gjj
 */
public class ViewROCDialog extends javax.swing.JDialog {

    /** Creates new form ViewROCDialog */
    public ViewROCDialog(java.awt.Frame parent, boolean modal,
            ResultInterpreter ri) {
        super(parent, modal);
        initComponents();
        rocTextArea.setText(formatResult(ri));
    }

    private String formatResult(ResultInterpreter ri) {
        if (ri==null)
            return "";

        StringBuilder sb = new StringBuilder();

        if (ri.tprAvailable()) {
            sb.append(String.format("AUC: %.6f\n", ri.auc()));
            sb.append(String.format("%20s%20s%20s\n", "FPR=1-Specificity",
                    "TPR=Sensitifity","Prediction Score"));
        } else {
            sb.append(String.format("%20s%20s\n", "TPR=Sensitifity","Prediction Score"));
        }

        double[][] res = ri.getOriginalROC();
        //double[][] res = ri.getROCAtIntegralFprPercentage();
        for (int i=0; i<res[0].length; i++) {
            if (ri.tprAvailable()) {
                sb.append(String.format("%20.6f%20.6f%20.6f\n", res[0][i], res[1][i], res[2][i]));
            } else {
                sb.append(String.format("%20.6f%20.6f\n", res[0][i], res[1][i]));
            }
        }

        return sb.toString();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        javax.swing.JScrollPane rocScrollPane = new javax.swing.JScrollPane();
        rocTextArea = new javax.swing.JTextArea();
        javax.swing.JButton closeButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("ROC");
        getContentPane().setLayout(new java.awt.GridBagLayout());

        rocScrollPane.setPreferredSize(new java.awt.Dimension(400, 800));

        rocTextArea.setColumns(20);
        rocTextArea.setEditable(false);
        rocTextArea.setRows(5);
        rocScrollPane.setViewportView(rocTextArea);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
        getContentPane().add(rocScrollPane, gridBagConstraints);

        closeButton.setText("Close");
        closeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                closeButtonActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
        getContentPane().add(closeButton, gridBagConstraints);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeButtonActionPerformed
        setVisible(false);
        dispose();
    }//GEN-LAST:event_closeButtonActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextArea rocTextArea;
    // End of variables declaration//GEN-END:variables

}
